.\" Man page generated from reStructuredText.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "GDAL_GRID" "1" "Feb 08, 2024" "" "GDAL"
.SH NAME
gdal_grid \- Creates regular grid from the scattered data.
.SH SYNOPSIS
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
gdal_grid [\-\-help] [\-\-help\-general]
          [\-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/
          CInt16/CInt32/CFloat32/CFloat64}]
          [\-oo <NAME>=<VALUE>]...
          [\-of <format>] [\-co <NAME>=<VALUE>]...
          [\-zfield <field_name>] [\-z_increase <increase_value>] [\-z_multiply <multiply_value>]
          [\-a_srs <srs_def>] [\-spat <xmin> <ymin> <xmax> <ymax>]
          [\-clipsrc <xmin> <ymin> <xmax> <ymax>|<WKT>|<datasource>|spat_extent]
          [\-clipsrcsql <sql_statement>] [\-clipsrclayer <layer>]
          [\-clipsrcwhere <expression>]
          [\-l <layername>]... [\-where <expression>] [\-sql <select_statement>]
          [\-txe <xmin> <xmax>] [\-tye <ymin> <ymax>] [\-tr <xres> <yres>] [\-outsize <xsize> <ysize>]
          [\-a {<algorithm>[[:<parameter1>=<value1>]...]}] [\-q]
          <src_datasource> <dst_filename>
.ft P
.fi
.UNINDENT
.UNINDENT
.SH DESCRIPTION
.sp
This program creates a regular grid (raster) from the scattered data read from
the OGR datasource. Input data will be interpolated to fill grid nodes with
values, you can choose from various interpolation methods.
.sp
It is possible to set the \fI\%GDAL_NUM_THREADS\fP
configuration option to parallelize the processing. The value to specify is
the number of worker threads, or \fBALL_CPUS\fP to use all the cores/CPUs of the
computer.
.INDENT 0.0
.TP
.B \-\-help
Show this help message and exit
.UNINDENT
.INDENT 0.0
.TP
.B \-\-help\-general
Gives a brief usage message for the generic GDAL commandline options and exit.
.UNINDENT
.INDENT 0.0
.TP
.B \-ot <type>
Force the output image bands to have a specific data type supported by the
driver, which may be one of the following: \fBByte\fP, \fBInt8\fP, \fBUInt16\fP,
\fBInt16\fP, \fBUInt32\fP, \fBInt32\fP, \fBUInt64\fP, \fBInt64\fP, \fBFloat32\fP, \fBFloat64\fP, \fBCInt16\fP,
\fBCInt32\fP, \fBCFloat32\fP or \fBCFloat64\fP\&.
.UNINDENT
.INDENT 0.0
.TP
.B \-of <format>
Select the output format. Starting with GDAL 2.3, if not specified, the
format is guessed from the extension (previously was GTiff). Use the short
format name.
.UNINDENT
.INDENT 0.0
.TP
.B \-txe <xmin> <xmax>
Set georeferenced X extents of output file to be created.
.UNINDENT
.INDENT 0.0
.TP
.B \-tye <ymin> <ymax>
Set georeferenced Y extents of output file to be created.
.UNINDENT
.INDENT 0.0
.TP
.B \-tr <xres> <yres>
Set output file resolution (in target georeferenced units).
Note that \fI\%\-tr\fP just works in combination with a valid input from \fI\%\-txe\fP and \fI\%\-tye\fP
.sp
New in version 3.2.

.UNINDENT
.INDENT 0.0
.TP
.B \-outsize <xsize> <ysize>
Set the size of the output file in pixels and lines.
Note that \fI\%\-outsize\fP cannot be used with \fI\%\-tr\fP
.UNINDENT
.INDENT 0.0
.TP
.B \-a_srs <srs_def>
Override the projection for the
output file.  The \fIsrs_def\fP may be any of the usual GDAL/OGR forms,
complete WKT, PROJ.4, EPSG:n or a file containing the WKT.
No reprojection is done.
.UNINDENT
.INDENT 0.0
.TP
.B \-zfield <field_name>
Identifies an attribute field
on the features to be used to get a Z value from. This value overrides the Z value
read from the feature geometry record (naturally, if you have a Z value in
the geometry, otherwise you have no choice and should specify a field name
containing a Z value).
.UNINDENT
.INDENT 0.0
.TP
.B \-z_increase <increase_value>
Addition to the attribute field
on the features to be used to get a Z value from. The addition should be the same
unit as the Z value. The result value will be Z value + Z increase value. The default value is 0.
.UNINDENT
.INDENT 0.0
.TP
.B \-z_multiply <multiply_value>
This is multiplication
ratio for the Z field. This can be used for a shift from e.g. feet to meters or from
elevation to depth. The result value will be (Z value + Z increase value) * Z multiply value.
The default value is 1.
.UNINDENT
.INDENT 0.0
.TP
.B \-a {<algorithm>[[:<parameter1>=<value1>]...]}
Set the interpolation algorithm or data metric name and (optionally)
its parameters. See the \fI\%Interpolation algorithms\fP and \fI\%Data metrics\fP
sections for further discussion of available options.
.UNINDENT
.INDENT 0.0
.TP
.B \-spat <xmin> <ymin> <xmax> <ymax>
Adds a spatial filter
to select only features contained within the bounding box described by
(xmin, ymin) \- (xmax, ymax).
.UNINDENT
.INDENT 0.0
.TP
.B \-clipsrc [<xmin> <ymin> <xmax> <ymax>]|<WKT>|<datasource>|spat_extent
Adds a spatial filter to select only features contained within the
specified bounding box (expressed in source SRS), WKT geometry (POLYGON or
MULTIPOLYGON), from a datasource or to the spatial extent of the \fI\%\-spat\fP
option if you use the \fBspat_extent\fP keyword. When specifying a
datasource, you will generally want to use it in combination with the
\fI\%\-clipsrclayer\fP, \fI\%\-clipsrcwhere\fP or \fI\%\-clipsrcsql\fP
options.
.UNINDENT
.INDENT 0.0
.TP
.B \-clipsrcsql <sql_statement>
Select desired geometries using an SQL query instead.
.UNINDENT
.INDENT 0.0
.TP
.B \-clipsrclayer <layername>
Select the named layer from the source clip datasource.
.UNINDENT
.INDENT 0.0
.TP
.B \-clipsrcwhere <expression>
Restrict desired geometries based on an attribute query.
.UNINDENT
.INDENT 0.0
.TP
.B \-l <layername>
Indicates the layer(s) from the
datasource that will be used for input features.  May be specified multiple
times, but at least one layer name or a \fI\%\-sql\fP option must be
specified.
.UNINDENT
.INDENT 0.0
.TP
.B \-where <expression>
An optional SQL WHERE style query expression to be applied to select features
to process from the input layer(s).
.UNINDENT
.INDENT 0.0
.TP
.B \-sql <select_statement>
An SQL statement to be evaluated against the datasource to produce a
virtual layer of features to be processed.
.UNINDENT
.INDENT 0.0
.TP
.B \-oo <NAME>=<VALUE>
New in version 3.7.

.sp
Source dataset open option (format specific)
.UNINDENT
.INDENT 0.0
.TP
.B \-co <NAME>=<VALUE>
Many formats have one or more optional creation options that can be
used to control particulars about the file created. For instance,
the GeoTIFF driver supports creation options to control compression,
and whether the file should be tiled.
.sp
The creation options available vary by format driver, and some
simple formats have no creation options at all. A list of options
supported for a format can be listed with the
\fI\%\-\-formats\fP
command line option but the documentation for the format is the
definitive source of information on driver creation options.
See \fI\%Raster drivers\fP format
specific documentation for legal creation options for each format.
.UNINDENT
.INDENT 0.0
.TP
.B \-q
Suppress progress monitor and other non\-error output.
.UNINDENT
.INDENT 0.0
.TP
.B <src_datasource>
Any OGR supported readable datasource.
.UNINDENT
.INDENT 0.0
.TP
.B <dst_filename>
The GDAL supported output file.
.UNINDENT
.SH INTERPOLATION ALGORITHMS
.sp
There are a number of interpolation algorithms to choose from.
.sp
More details about them can also be found in \fI\%GDAL Grid Tutorial\fP
.SS invdist
.sp
Inverse distance to a power. This is the default algorithm. It has the following
parameters:
.INDENT 0.0
.IP \(bu 2
\fBpower\fP: Weighting power (default 2.0).
.IP \(bu 2
\fBsmoothing\fP: Smoothing parameter (default 0.0).
.IP \(bu 2
\fBradius1\fP: The first radius (X axis if rotation angle is 0)
of the search ellipse. Set this parameter to zero to use the whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius2\fP: The second radius (Y axis if rotation angle is 0)
of the search ellipse. Set this parameter to zero to use the whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius\fP: Set first and second radius (mutually exclusive with radius1 and radius2).
Default is 0.0. Added in GDAL 3.6
.IP \(bu 2
\fBangle\fP: Angle of search ellipse rotation in degrees
(counter clockwise, default 0.0).
.IP \(bu 2
\fBmax_points\fP: Maximum number of data points to use. Do not
search for more points than this number. This is only used if the search ellipse
is set (both radii are non\-zero). Zero means that all found points should
be used. Default is 0.
.IP \(bu 2
\fBmin_points\fP: Minimum number of data points to use. If less
amount of points found the grid node considered empty and will be filled with
NODATA marker. This is only used if search ellipse is set (both radii are
non\-zero). Default is 0.
.IP \(bu 2
\fBmax_points_per_quadrant\fP: Maximum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
When specified, this actually uses invdistnn implementation.
.IP \(bu 2
\fBmin_points_per_quadrant\fP: Minimum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
When specified, this actually uses invdistnn implementation.
.IP \(bu 2
\fBnodata\fP: NODATA marker to fill empty points (default
0.0).
.UNINDENT
.SS invdistnn
.sp
New in version 2.1.

.sp
Inverse distance to a power with nearest neighbor searching, ideal when
max_points is used. It has following parameters:
.INDENT 0.0
.IP \(bu 2
\fBpower\fP: Weighting power (default 2.0).
.IP \(bu 2
\fBsmoothing\fP: Smoothing parameter (default 0.0).
.IP \(bu 2
\fBradius\fP: The radius of the search circle, which should be
non\-zero. Default is 1.0.
.IP \(bu 2
\fBmax_points\fP: Maximum number of data points to use. Do not
search for more points than this number. Found points will be ranked from
nearest to furthest distance when weighting. Default is 12.
.IP \(bu 2
\fBmin_points\fP: Minimum number of data points to use. If less
amount of points found the grid node is considered empty and will be filled
with NODATA marker. Default is 0.
.IP \(bu 2
\fBmax_points_per_quadrant\fP: Maximum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
When specified, the algorithm will only take into account up to max_points_per_quadrant
points for each of the right\-top, left\-top, right\-bottom and right\-top quadrant
relative to the point being interpolated.
.IP \(bu 2
\fBmin_points_per_quadrant\fP: Minimum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
If that number is not reached, the point being interpolated will be set with
the NODATA marker.
When specified, the algorithm will collect at least min_points_per_quadrant
points for each of the right\-top, left\-top, right\-bottom and right\-top quadrant
relative to the point being interpolated.
.IP \(bu 2
\fBnodata\fP: NODATA marker to fill empty points (default
0.0).
.UNINDENT
.sp
When \fBmin_points_per_quadrant\fP or \fBmax_points_per_quadrant\fP is specified, the
search will start with the closest point to the point being interpolated
from the first quadrant, then the closest point to the point being interpolated
from the second quadrant, etc. up to the 4th quadrant, and will continue with
the next closest point in the first quadrant, etc. until \fBmax_points\fP and/or
\fBmax_points_per_quadrant\fP thresholds are reached.
.SS average
.sp
Moving average algorithm. It has following parameters:
.INDENT 0.0
.IP \(bu 2
\fBradius1\fP: The first radius (X axis if rotation angle is 0)
of search ellipse. Set this parameter to zero to use whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius2\fP: The second radius (Y axis if rotation angle is 0)
of search ellipse. Set this parameter to zero to use whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius\fP: Set first and second radius (mutually exclusive with radius1 and radius2).
Default is 0.0. Added in GDAL 3.6
.IP \(bu 2
\fBangle\fP: Angle of search ellipse rotation in degrees
(counter clockwise, default 0.0).
.IP \(bu 2
\fBmax_points\fP: Maximum number of data points to use. Do not
search for more points than this number. Found points will be ranked from
nearest to furthest distance when weighting. Default is 0. Added in GDAL 3.6
Only taken into account if one or both of \fBmin_points_per_quadrant\fP or \fBmax_points_per_quadrant\fP
is specified
.IP \(bu 2
\fBmin_points\fP: Minimum number of data points to use. If less
amount of points found the grid node considered empty and will be filled with
NODATA marker. Default is 0.
.IP \(bu 2
\fBmax_points_per_quadrant\fP: Maximum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
When specified, the algorithm will only take into account up to max_points_per_quadrant
points for each of the right\-top, left\-top, right\-bottom and right\-top quadrant
relative to the point being interpolated.
.IP \(bu 2
\fBmin_points_per_quadrant\fP: Minimum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
If that number is not reached, the point being interpolated will be set with
the NODATA marker.
When specified, the algorithm will collect at least min_points_per_quadrant
points for each of the right\-top, left\-top, right\-bottom and right\-top quadrant
relative to the point being interpolated.
.IP \(bu 2
\fBnodata\fP: NODATA marker to fill empty points (default
0.0).
.UNINDENT
.sp
Note, that it is essential to set search ellipse for moving average method. It
is a window that will be averaged when computing grid nodes values.
.sp
When \fBmin_points_per_quadrant\fP or \fBmax_points_per_quadrant\fP is specified, the
search will start with the closest point to the point being interpolated
from the first quadrant, then the closest point to the point being interpolated
from the second quadrant, etc. up to the 4th quadrant, and will continue with
the next closest point in the first quadrant, etc. until \fBmax_points\fP and/or
\fBmax_points_per_quadrant\fP thresholds are reached.
.SS nearest
.sp
Nearest neighbor algorithm. It has following parameters:
.INDENT 0.0
.IP \(bu 2
\fBradius1\fP: The first radius (X axis if rotation angle is 0)
of search ellipse. Set this parameter to zero to use whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius2\fP: The second radius (Y axis if rotation angle is 0)
of search ellipse. Set this parameter to zero to use whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius\fP: Set first and second radius (mutually exclusive with radius1 and radius2).
Default is 0.0. Added in GDAL 3.6
.IP \(bu 2
\fBangle\fP: Angle of search ellipse rotation in degrees
(counter clockwise, default 0.0).
.IP \(bu 2
\fBnodata\fP: NODATA marker to fill empty points (default
0.0).
.UNINDENT
.SS linear
.sp
New in version 2.1.

.sp
Linear interpolation algorithm.
.sp
The Linear method performs linear interpolation by computing a Delaunay
triangulation of the point cloud, finding in which triangle of the triangulation
the point is, and by doing linear interpolation from its barycentric coordinates
within the triangle.
If the point is not in any triangle, depending on the radius, the
algorithm will use the value of the nearest point or the nodata value.
.sp
It has following parameters:
.INDENT 0.0
.IP \(bu 2
\fBradius\fP: In case the point to be interpolated does not fit
into a triangle of the Delaunay triangulation, use that maximum distance to search a nearest
neighbour, or use nodata otherwise. If set to \-1, the search distance is infinite.
If set to 0, nodata value will be always used. Default is \-1.
.IP \(bu 2
\fBnodata\fP: NODATA marker to fill empty points (default
0.0).
.UNINDENT
.SH DATA METRICS
.sp
Besides the interpolation functionality \fBgdal_grid\fP can be used to compute
some data metrics using the specified window and output grid geometry. These
metrics are:
.INDENT 0.0
.IP \(bu 2
\fBminimum\fP: Minimum value found in grid node search ellipse.
.IP \(bu 2
\fBmaximum\fP: Maximum value found in grid node search ellipse.
.IP \(bu 2
\fBrange\fP: A difference between the minimum and maximum values
found in grid node search ellipse.
.IP \(bu 2
\fBcount\fP:  A number of data points found in grid node search ellipse.
.IP \(bu 2
\fBaverage_distance\fP: An average distance between the grid
node (center of the search ellipse) and all of the data points found in grid
node search ellipse.
.IP \(bu 2
\fBaverage_distance_pts\fP: An average distance between the data
points found in grid node search ellipse. The distance between each pair of
points within ellipse is calculated and average of all distances is set as a
grid node value.
.UNINDENT
.sp
All the metrics have the same set of options:
.INDENT 0.0
.IP \(bu 2
\fBradius1\fP: The first radius (X axis if rotation angle is 0)
of search ellipse. Set this parameter to zero to use whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius2\fP: The second radius (Y axis if rotation angle is 0)
of search ellipse. Set this parameter to zero to use whole point array.
Default is 0.0.
.IP \(bu 2
\fBradius\fP: Set first and second radius (mutually exclusive with radius1 and radius2).
Default is 0.0. Added in GDAL 3.6
.IP \(bu 2
\fBangle\fP: Angle of search ellipse rotation in degrees
(counter clockwise, default 0.0).
.IP \(bu 2
\fBmin_points\fP: Minimum number of data points to use. If less
amount of points found the grid node considered empty and will be filled with
NODATA marker. This is only used if search ellipse is set (both radii are
non\-zero). Default is 0.
.IP \(bu 2
\fBmax_points_per_quadrant\fP: Maximum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
When specified, the algorithm will only take into account up to max_points_per_quadrant
points for each of the right\-top, left\-top, right\-bottom and right\-top quadrant
relative to the point being interpolated.
.IP \(bu 2
\fBmin_points_per_quadrant\fP: Minimum number of data points to use per quadrant.
Default is 0. Added in GDAL 3.6.
If that number is not reached, the point being interpolated will be set with
the NODATA marker.
When specified, the algorithm will collect at least min_points_per_quadrant
points for each of the right\-top, left\-top, right\-bottom and right\-top quadrant
relative to the point being interpolated.
.IP \(bu 2
\fBnodata\fP: NODATA marker to fill empty points (default
0.0).
.UNINDENT
.sp
When \fBmin_points_per_quadrant\fP or \fBmax_points_per_quadrant\fP is specified, the
search will start with the closest point to the point being interpolated
from the first quadrant, then the closest point to the point being interpolated
from the second quadrant, etc. up to the 4th quadrant, and will continue with
the next closest point in the first quadrant, etc. until \fBmax_points\fP and/or
\fBmax_points_per_quadrant\fP thresholds are reached.
.SH READING COMMA SEPARATED VALUES
.sp
Often you have a text file with a list of comma separated XYZ values to work
with (so called CSV file). You can easily use that kind of data source in
\fBgdal_grid\fP\&. All you need is create a virtual dataset header (VRT) for you CSV
file and use it as input datasource for \fBgdal_grid\fP\&. You can find details
on VRT format at \fI\%VRT \-\- Virtual Format\fP description page.
.sp
Here is a small example. Let we have a CSV file called \fIdem.csv\fP
containing
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
Easting,Northing,Elevation
86943.4,891957,139.13
87124.3,892075,135.01
86962.4,892321,182.04
87077.6,891995,135.01
\&...
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
For above data we will create \fIdem.vrt\fP header with the following
content:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
<OGRVRTDataSource>
    <OGRVRTLayer name=\(dqdem\(dq>
        <SrcDataSource>dem.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <GeometryField encoding=\(dqPointFromColumns\(dq x=\(dqEasting\(dq y=\(dqNorthing\(dq z=\(dqElevation\(dq/>
    </OGRVRTLayer>
</OGRVRTDataSource>
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
This description specifies so called 2.5D geometry with three coordinates X, Y
and Z. Z value will be used for interpolation. Now you can use \fIdem.vrt\fP
with all OGR programs (start with \fI\%ogrinfo\fP to test that everything works
fine). The datasource will contain single layer called \fI\(dqdem\(dq\fP filled
with point features constructed from values in CSV file. Using this technique
you can handle CSV files with more than three columns, switch columns, etc.
.sp
If your CSV file does not contain column headers then it can be handled in the
following way:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
<GeometryField encoding=\(dqPointFromColumns\(dq x=\(dqfield_1\(dq y=\(dqfield_2\(dq z=\(dqfield_3\(dq/>
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The \fI\%Comma Separated Value (.csv)\fP description page contains
details on CSV format supported by GDAL/OGR.
.SH C API
.sp
This utility is also callable from C with \fI\%GDALGrid()\fP\&.
.SH EXAMPLES
.sp
The following would create raster TIFF file from VRT datasource described in
\fI\%Reading comma separated values\fP section using the inverse distance to a power method.
Values to interpolate will be read from Z value of geometry record.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
gdal_grid \-a invdist:power=2.0:smoothing=1.0 \-txe 85000 89000 \-tye 894000 890000 \-outsize 400 400 \-of GTiff \-ot Float64 \-l dem dem.vrt dem.tiff
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The next command does the same thing as the previous one, but reads values to
interpolate from the attribute field specified with \fB\-zfield\fP option
instead of geometry record. So in this case X and Y coordinates are being
taken from geometry and Z is being taken from the \fI\(dqElevation\(dq\fP field.
The \fI\%GDAL_NUM_THREADS\fP is also set to parallelize the computation.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
gdal_grid \-zfield \(dqElevation\(dq \-a invdist:power=2.0:smoothing=1.0 \-txe 85000 89000 \-tye 894000 890000 \-outsize 400 400 \-of GTiff \-ot Float64 \-l dem dem.vrt dem.tiff \-\-config GDAL_NUM_THREADS ALL_CPUS
.ft P
.fi
.UNINDENT
.UNINDENT
.SH AUTHOR
Andrey Kiselev <dron@ak4719.spb.edu>
.SH COPYRIGHT
1998-2024
.\" Generated by docutils manpage writer.
.
